package org.scohen.juploadr.uploadapi.abilities;

import java.io.File;
import java.util.regex.Pattern;

import org.scohen.juploadr.ui.thumbnail.SwtThumbnailBuilder;
import org.scohen.juploadr.ui.thumbnail.ThumbnailBuilder;

public class UploadAbilities implements AbilitiesList {
    private String[] uploadFileTypes = { ".jpg", ".gif", ".png" };
    private Pattern thumbnailRegex;

    public UploadAbilities() {
        StringBuffer sb = new StringBuffer(".*(");
        for (int i = 0; i < uploadFileTypes.length; i++) {
            sb.append("(\\");
            sb.append(uploadFileTypes[i]);
            sb.append(")");
            if (i < uploadFileTypes.length - 1) {
                sb.append("|");
            }

        }
        sb.append(")");
        thumbnailRegex = Pattern.compile(sb.toString(),Pattern.CASE_INSENSITIVE);
    }

    public String[] getUploadFileTypes() {
        return uploadFileTypes;
    }

    public String[] getUploadFileTypesAsGlobs() {
        String[] globs = new String[uploadFileTypes.length];
        for (int i = 0; i < uploadFileTypes.length; i++) {
            globs[i] = "*" + uploadFileTypes[i];
        }
        return globs;
    }

    public ThumbnailBuilder getThumbnailBuilder(File file) throws FileTypeNotSupportedException {
            return new SwtThumbnailBuilder();
    }

    public boolean allDisabled() {
        // TODO Auto-generated method stub
        return false;
    }

    public void notified(AbilityNotification n) {
        // TODO Auto-generated method stub

    }

    public static void main(String[] args) {
        String re = ".*((\\.jpg)|(\\.gif)|(\\.png))";
        Pattern p = Pattern.compile(re);
        String[] files = { "Foo.jpg", "foo.png", "foo_bar.gif", "foo_bar_baz.pdf" };
        for (int i = 0; i < files.length; i++) {
            String file = files[i];
            System.out.println(file + "?" + p.matcher(file).matches());

        }
    }
}
